/**
 * @class   wosh::MessageContent
 * @brief   Base abstract class for contents of a Message
 *
 ****************************************************************************
 * @version $Id: MessageContent.h 2827 2010-08-02 11:01:48Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Core_MessageContent_H__
 #define __WOSH_Core_MessageContent_H__

 #include <woshDefs.h>
 #include <core/Serialization.h>
 #include <string>


namespace wosh {

class Request;
class Response;
class Fact;
class Notification;
class SystemError;

// virtual ISerializable ==>> MSC CRASH on clone() cos of wrong member pointer!!
// QUESTION: is it a MSC BUG??? (it looks like, G++ works fine as espected)

class MessageContent : public ISerializable
 {
	WOSH_SERIALIZABLE_ABSTRACT(wosh::MessageContent)

	public:
		/// types of message's content
		enum TYPE {
			GENERIC			= 0x0000,
			FACT			= 0x0001,
			ACTION			= 2,
			RESPONSE		= 4,
			PROPERTY		= 8,
			AUTOMATION		= 16,
			NOTIFICATION	= 32,
			SYSTEM			= 256,
			UNKNOWN			= 512
		};

	public:
		/**
		 * @brief  Empty constructor.
		 */
		MessageContent() { }

MessageContent( const MessageContent& ) { }

		/**
		 * @brief  Empty destructor.
		 */
		virtual ~MessageContent() { }


/** @name Getters
 * @{
 ******************************************************************************/
	public:
		/**
		 * @brief  Evaluate if current object is a Request. Provided for convenience.
		 * @return true when MessageContent's type is ACTION
		 */
		inline bool isRequest() const							{ return (this->getType() == MessageContent::ACTION); }

		/**
		 * @brief  Evaluate if current object is a Response. Provided for convenience.
		 * @return true when MessageContent's type is RESPONSE
		 */
		inline bool isResponse() const							{ return (this->getType() == MessageContent::RESPONSE); }

		/**
		 * @brief  Evaluate if current object is a Property. Provided for convenience.
		 * @return true when MessageContent's type is PROPERTY
		 */
		inline bool isProperty() const							{ return (this->getType() == MessageContent::PROPERTY); }

		/**
		 * @brief  Evaluate if current object is a Fact. Provided for convenience.
		 * @return true when MessageContent's type is FACT
		 */
		inline bool isFact() const								{ return (this->getType() == MessageContent::FACT); }

		/**
		 * @brief  Evaluate if current object is a Notification. Provided for convenience.
		 * @return true when MessageContent's type is NOTIFICATION
		 */
		inline bool isNotification() const						{ return (this->getType() == MessageContent::NOTIFICATION); }

		/**
		 * @brief  Evaluate if current object is a SystemError. Provided for convenience.
		 * @return true when MessageContent's type is SYSTEM
		 */
		inline bool isSystemError() const						{ return (this->getType() == MessageContent::SYSTEM); }


	public:
		/**
		 * @brief  Cast the current object to a Request. Provided for convenience.
		 * @return pointer to current object casted as (constant) Request, NULL on casting error.
		 */
		virtual const Request* asRequest() const;

		/**
		 * @brief  Cast the current object to a Response. Provided for convenience.
		 * @return pointer to current object casted as (constant) Response, NULL on casting error.
		 */
		virtual const Response* asResponse() const;

		/**
		 * @brief  Cast the current object to a Fact. Provided for convenience.
		 * @return pointer to current object casted as (constant) Fact, NULL on casting error.
		 */
		virtual const Fact* asFact() const;

		/**
		 * @brief  Cast the current object to a Notification. Provided for convenience.
		 * @return pointer to current object casted as (constant) Notification, NULL on casting error.
		 */
		virtual const Notification* asNotification() const;

		/**
		 * @brief  Cast the current object to a SystemError. Provided for convenience.
		 * @return pointer to current object casted as (constant) SystemError, NULL on casting error.
		 */
		virtual const SystemError* asSystemError() const;

//@}
/** @name Interface Methods
 * @{
 ******************************************************************************/
	public:
		/**
		 * @brief  Get MessageContent::TYPE of implementations.
		 * @return returns a constat type for each implementation of this class-interface
		 * @see    MessageContent::TYPE
		 */
		virtual TYPE getType() const = 0 ;

		std::string getTypeAsString() const						{ return MessageContent::getTypeAsString(this->getType()); }

//@}
/** @name Helpers
 * @{
 ******************************************************************************/
	public:
		static std::string getTypeAsString(TYPE type);

		static TYPE getTypeFromString( const std::string& type_string );

//@}


}; // class def

}; // namespace wosh

#endif //__WOSH_Core_MessageContent_H__
